package SolodkovDA.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class FilmAddPage extends InternalPage {

	public FilmAddPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "name")
	private WebElement titleField;

  @FindBy(name = "year")
  private WebElement yearField;

  @FindBy(name = "submit")
  private WebElement submitButton;
  
  @FindBy(css = "label.error")
  private WebElement requiredLabel;
  
  
  public FilmAddPage setTitleField(String text) {
	    titleField.sendKeys(text);
	    return this;
	  }

	  public FilmAddPage setYearField(String text) {
	    yearField.sendKeys(text);
	    return this;
	  }

	  public void clickSubmitButton() {
	    submitButton.click();
	  }

	  public FilmAddPage ensurePageLoaded() {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.id("imdbsearchform")));
	    return this;
	  }
	  
	  public FilmAddPage checkRequiredLabel() {
		  wait.until(presenceOfElementLocated(By.cssSelector("label.error")));
		  wait.until(presenceOfElementLocated( By.xpath("//form[@id='updateform']/table/tbody/tr[4]/td[2]/label")));
		  return this;
		  }
	
	
}